home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / s_to_z / tpack / usernetw.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  9.0 KB  |  228 lines

  1. unit UserNetW;
  2.  
  3. {BASED ON USERINFO.. Read that first.}
  4.  
  5. {REQUIRES 'NOVELL' TO BE DEFINED FOR NOVEL FEATURES TO WORK. WILL BE FIXED.}
  6.  
  7. {COMPLETELY RIPPED OUT OF 'THE DELPHI SCREEN SAVER', REGURGITATED AND REINTEGRATED MY WAY.}
  8. {I added a tiny bit of code to avoid triggering password lockout in the Checkpassword but
  9. did not get rid of the ugly conditionals yet. however! once initialized this component will
  10. give YOU the server name!.. If you're going to always run on novell, this code is fine,
  11. if not have it check for the DLL's existance before doing the update. PRODUCTION/not library
  12. quality code; but it now is a generic enough component to spark some ideas. share them.}
  13.  
  14. {-----------------------------------------------------------------------------------------}
  15. { USERNOV                                                                                 }
  16. {-----------------------------------------------------------------------------------------}
  17.  
  18. interface
  19.  
  20. uses
  21.   Classes,
  22.   PasUtils
  23.   ,UserInfo;
  24.  
  25. Const
  26.   NetWorkPasswordOk = 0;
  27.   NetWorkPasswordLockOut = 197;
  28.  
  29. Type
  30.   TNetWareUserInfo = class(TUserInfo)
  31.   {wraps some netware calls for easy access (gets the servername!) and can validate a
  32.   password against the users password}
  33.   private
  34.     fConnectID,
  35.     fConnectNumber : LongInt;                                { Default connection id }
  36.     pServerName  :PString;
  37.     pLoginName   :PString;
  38.     pFullName    :PString;
  39.     pLoginTime   :PString;
  40.   protected
  41.     function GetServerName:String;
  42.     function GetLoginName:String;
  43.     function GetFullName:String;
  44.     function GetLoginTime:String;
  45.     procedure SetNoString(const Value:String);
  46.   public
  47.     Constructor Create(aOwner:TComponent); Override;
  48.     Destructor Destroy; Override;
  49.     function UpdateOK:boolean; Override;
  50.     Function HasPassWord:Boolean;
  51.     Function CheckPassWord(const Value:String):Integer;
  52.   published
  53.     property ConnectID:Longint read fConnectID;
  54.     property ConnectNumber:Longint read fConnectNumber;
  55.  
  56.     property ServerName:String read GetServerName write SetNoString;
  57.     property LoginName:String read GetLoginName write SetNoString;
  58.     property FullName:String read GetFullName write SetNoString;
  59.     property LoginTime: String read GetLoginTime write SetNoString;
  60.     end;
  61.  
  62. {$IFDEF NOVELL}
  63. Function GetConnectionNumber : Integer;                    { Get novell connection number }
  64. Function GetConnectionInformation(ConId : LongInt;         { Get Novell connection info }
  65.            UserName : PChar; Var ObjType : Integer; Var ObjID : LongInt; LoginTime : PChar) : Integer;
  66. Function GetDefaultConnectionID : Integer;                 { Get Novell Default Connection ID }
  67. Function GetFileServerName(DefConID : LongInt;             { Get Novell File server Name }
  68.            FsName : PChar) : Integer;
  69. Function ReadPropertyValue(szUserName : PChar;             { Read a Novell property Value }
  70.            ObjType : Integer;szPropName : PChar;SegNum :  Integer;szLongName : PChar;
  71.            Var iMoreSegs : Char;Var iMoreFlags : Char) : Integer;
  72. Function VerifyBinderyObjectPassword(UserName : PChar;     { Verify a password against a bindery object }
  73.            BinType  : Integer; PassWord : PChar) : Integer;
  74. {$ENDIF}
  75.  
  76.  
  77. implementation
  78.  
  79. uses
  80.   Controls
  81.   ,SysUtils
  82.   ,Forms;
  83.  
  84. {-----------------------------------------------------------------------------------------}
  85. { NETWARE USER INFO                                                                       }
  86. {-----------------------------------------------------------------------------------------}
  87.  
  88. {$IFDEF NOVELL}
  89. Function GetConnectionNumber;         external 'NWNETAPI';
  90. Function GetConnectionInformation;    external 'NWNETAPI';
  91. Function GetDefaultConnectionID;      external 'NWNETAPI';
  92. Function GetFileServerName;           external 'NWNETAPI';
  93. Function ReadPropertyValue;           external 'NWNETAPI';    { Declare novell calls }
  94. Function VerifyBinderyObjectPassword; external 'NWNETAPI';
  95. {$ENDIF}
  96.  
  97. {-----------------------------------------------------------------------------------------}
  98. { OBJECT CREATION                                                                         }
  99. {-----------------------------------------------------------------------------------------}
  100.  
  101. Constructor TNetWareUserInfo.Create(aOwner:TComponent);
  102. begin
  103.   inherited Create(aOwner);
  104. {  Options:=[uifUpdateOnLoad,uifUpdateOnGet];}
  105.   pServerName:=NullStr;
  106.   pLoginName:=NullStr;
  107.   pFullName:=NullStr;
  108.   pLoginTime:=NullStr;
  109. end;
  110.  
  111. Destructor TNetWareUserInfo.Destroy;
  112. begin
  113.   DisposeStr(pLoginTime);
  114.   DisposeStr(pFullName);
  115.   DisposeStr(pLoginName);
  116.   DisposeStr(pServerName);
  117.   inherited Destroy;
  118. end;
  119.  
  120.  
  121. function TNetWareUserInfo.UpdateOK:boolean;
  122. var
  123.   fzServerName  : array [0..50] of Char;                   { File server Name }
  124.   fzLoginName   : array [0..50] of Char;                   { User Name }
  125.   fzFullName    : array [0..127] of Char;                  { Fill Name }
  126.   fzLoginTime   : array [0..9] of Char;                    { Login Time }
  127.   iRc : Integer;                                           { Return Type }
  128.   iOtype   : Integer;                                      { Object Type }
  129.   iOID : LongInt;                                          { Object Id }
  130.   iMoreSegs, iMoreFlags : Char;                            { Local Flags }
  131. begin
  132.   Result:=inherited UpdateOK;
  133.   if not Result then
  134.     Exit;
  135. {$IFDEF NOVELL}
  136.   fzServerName[0] := #0;                                   { Null FS name }
  137.   fzLoginName[0] := #0;                                    { Null User Name }
  138.   fzFullName[0] := #0;                                     { Fill Name }
  139.   fzLoginTime[0] := #0;                                    { Login Time }
  140.   fConnectID := GetDefaultConnectionID;                    { Get default connection ID }
  141.   fConnectNumber:= GetConnectionNumber;                    { Get connection Number }
  142.   iRc := GetConnectionInformation(                         { Get connection info }
  143.            fConnectNumber,@fzLoginName[0],iOtype,iOID,fzLoginTime);
  144.   if fzLoginName[0] = #0 then Exit;                        { If No User Name, No Net thus exit }
  145.   iRc := GetFileServerName(fConnectID,fzServerName);       { Get FS name }
  146.   iRc := ReadPropertyValue(                                { Get the user's full Name }
  147.            fzLoginName,iOtype,'IDENTIFICATION',1,fzFullName,iMoreSegs,iMoreFlags);
  148.   MovePChar2PString(pServerName,fzServerName,false);
  149.   MovePChar2PString(pLoginName,fzLoginName,false);
  150.   MovePChar2PString(pFullName,fzFullName,false);
  151.   MovePChar2PString(pLoginTime,fzLoginTime,false);
  152. {$ENDIF}
  153. end;
  154.  
  155. {-----------------------------------------------------------------------------------------}
  156. { OBJECT FUNCTIONS                                                                        }
  157. {-----------------------------------------------------------------------------------------}
  158.  
  159. Function TNetWareUserInfo.HasPassWord:Boolean;
  160. {since calling the VerifyBinderyObjectPassword function multiple times with the wrong pw
  161. can trigger the network's intruder alert and leave the user locked out when the log back in
  162. we're using two constants to get the value only once. Perhaps there is a system message that
  163. kicks in when a user changes names while logged in, but this will kick in just once per run.}
  164. const
  165.   init:Boolean=True; {could make a property}
  166.   HasPW:Boolean=False;
  167. begin
  168.   if Init then begin
  169.     Init:=False;
  170.     HasPW:=CheckPassWord('')<>NetWorkPasswordOk;
  171.     end;
  172.   Result:=HasPW; {true if the user has a network password}
  173. end;
  174.  
  175. Function TNetWareUserInfo.CheckPassWord(const Value:String):Integer;
  176. var
  177.   Cursor:TCursor;
  178.   zPWD: PChar;
  179.   zLoginName: PChar;
  180. begin
  181. {$IFDEF NOVELL}
  182.   Cursor:= Screen.Cursor;
  183.   Screen.Cursor := crHourGlass;                            { Start waiting }
  184.   zPWD:=MakePChar(Value);
  185.   zLoginName:=MakePChar(pLoginName^);
  186.   Result := VerifyBinderyObjectPassword(zLoginName,1,zPWD); { Verify against USER login name }
  187.   FreePChar(zLoginName);
  188.   FreePChar(zPWD);
  189.   Screen.Cursor := Cursor;
  190. {$ELSE}
  191.   Result:= NetWorkPasswordOk;
  192. {$ENDIF}
  193. end;
  194.  
  195. {-----------------------------------------------------------------------------------------}
  196. { PROPERTY PLUMBING                                                                       }
  197. {-----------------------------------------------------------------------------------------}
  198.  
  199. procedure TNetWareUserInfo.SetNoString(const Value:String);
  200. begin
  201. end;
  202.  
  203. function TNetWareUserInfo.GetServerName:String;
  204. begin
  205.   Result:=pServerName^;
  206. end;
  207.  
  208. function TNetWareUserInfo.GetLoginName:String;
  209. begin
  210.   Result:=pLoginName^;
  211. end;
  212.  
  213. function TNetWareUserInfo.GetFullName:String;
  214. begin
  215.   Result:=pFullName^;
  216. end;
  217.  
  218. function TNetWareUserInfo.GetLoginTime:String;
  219. begin
  220.   Result:=pLoginTime^;
  221. end;
  222.  
  223. {-----------------------------------------------------------------------------------------}
  224. {                                                                                         }
  225. {-----------------------------------------------------------------------------------------}
  226.  
  227. end.
  228.